package cn.mesmile.drools.controller;

import cn.mesmile.drools.common.R;
import cn.mesmile.drools.entity.Calculation;
import cn.mesmile.drools.entity.CreditCardApplyInfo;
import cn.mesmile.drools.service.RulesService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zb
 * @date 2021/7/26 0:01
 * @Description
 */
@RequestMapping("/api/v1/rules")
@RestController
public class RulesController {

    private final RulesService rulesService;

    public RulesController(RulesService rulesService) {
        this.rulesService = rulesService;
    }

    @GetMapping("/exec")
    public R exec(){
        rulesService.rule();
        try {
            Thread.sleep(3000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return R.data("success");
    }

    @GetMapping("/calculate")
    public R calculate(double wage){
        Calculation calculation = new Calculation();
        calculation.setWage(wage);
        Calculation calculate = rulesService.calculate(calculation);
        return R.data(calculate);
    }

    @GetMapping("/creditCardApply")
    public R creditCardApply(){
        CreditCardApplyInfo creditCardApplyInfo = new CreditCardApplyInfo();
        creditCardApplyInfo.setName("张三");
        creditCardApplyInfo.setSex("男");
        creditCardApplyInfo.setAge(20);
        creditCardApplyInfo.setEducation(CreditCardApplyInfo.EDUCATION_3);
        creditCardApplyInfo.setTelephone("1234567890");
        creditCardApplyInfo.setMonthlyIncome(16000);
        creditCardApplyInfo.setAddress("这是一个测试地址");
        creditCardApplyInfo.setHasHouse(true);
        creditCardApplyInfo.setHasCar(false);
        creditCardApplyInfo.setHasCreditCardCount(0);
        CreditCardApplyInfo result = rulesService.creditCardApply(creditCardApplyInfo);
        return R.data(result);
    }
}
